<template>
	<view class="body">
		<view class="course" @click="gocouse">
			<view class="left">
				<view class="lefttit">
					选择课程
				</view>		
				<view class="uni-input">{{title}}</view>
			</view>
			<view class="right">
				<p class="iconfont icon-more"></p>
			</view>
		</view>
		<view class="time">
			<p>上课时间</p>
			<view class="timeright">
				<view class="uni-input">今日{{time}}</view>
			</view>
		</view>
		<view class="remark">
			<view class="remarktit">
				备注
			</view>
			<textarea @blur="bindTextAreaBlur" placeholder="填写备注信息"/>
		</view>
		<view class="sumbit">
			<button type="default" @click="addleave">提交</button>
		</view>
		
	</view>
	
</template>

<script>
import {getcourse,addleavelist} from '../../api/index.js'
	export default {
	    data() {
			const currentDate = this.getDate({
			            format: true
			        })
	        return {
	           array: [],
			   title:'请选择',
			   time:'12:30',
	            index: 0,
				date: currentDate,
				params:{
					courseName:'',
					courseTableid:0,
					remarks:''
				}
	        }
	    },
		computed: {
		        startDate() {
		            return this.getDate('start');
		        },
		        endDate() {
		            return this.getDate('end');
		        }
		    },
			onLoad(options){
				console.log(JSON.parse(options.datas)||'')
				this.params.courseTableid=JSON.parse(options.datas).id
				this.title=JSON.parse(options.datas).coursename
				this.time=JSON.parse(options.datas).starttime
			},
	    methods: {
			gocouse(){
				uni.switchTab({
					url:"/pages/SelectCourses/Courses"
				})
			},
			async addleave(){
				console.log(this.params)
				let res = await addleavelist(this.params)
				if(res.errCode==10000){
					uni.showToast({
						msg:'请假成功!等待审核'
					})
					uni.navigateTo({
						url:"/pages/recess/recess"
					})
					
				}
				console.log(res)
			},
			 bindTextAreaBlur: function (e) {
						this.params.remarks=e.detail.value
			},
			bindTimeChange: function(e) {
			    this.time = e.detail.value
			 },
			
			getDate(type) {
			    const date = new Date();
			    let year = date.getFullYear();
			    let month = date.getMonth() + 1;
				let day = date.getDate();
			 
			    if (type === 'start') {
			        year = year - 60;
			    } else if (type === 'end') {
			        year = year + 2;
			    }
			    month = month > 9 ? month : '0' + month;
			    day = day > 9 ? day : '0' + day;
			    return `${year}-${month}-${day}`;
			}
	    }
	}
</script>

<style scoped lang="less">
	@import './addreserve.less';
</style>
